<template>
  <div class="custom-form">
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px" :key="showFormKey">
        <!-- 换班申请 -->
        <el-col :span="24">
          <el-form-item label-width="0" prop="field100ae92">
            <h2 align='center' style="color:undefined;font-size: nullpx;text-align: center">换班申请</h2>
          </el-form-item>
        </el-col>
        <!-- 角色ID -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('角色ID')" prop="F_RoleId">
            <el-input v-model="formData['F_RoleId']" placeholder="请输入角色ID" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 角色名称 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('角色名称')" prop="F_RoleName">
            <el-input v-model="formData['F_RoleName']" placeholder="请输入角色名称" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 地区 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('地区')" prop="F_Area">
            <el-input v-model="formData['F_Area']" placeholder="请输入地区" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 职级名称 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('职级名称')" prop="F_Job">
            <el-input v-model="formData['F_Job']" placeholder="请输入职级名称" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 部门名称 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('部门名称')">
            <el-input v-model="formData['F_DepartmentName']" placeholder="请输入部门名称" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 部门ID -->
        <el-col :span="24">
          <el-form-item :label="$t('部门')" prop="F_DepartmentId">
            <el-select v-model="formData['F_DepartmentId']" placeholder="请选择部门" filterable clearable
              @change="selectDepartMent" :style="{ width: '100%' }">
              <el-option v-for="(item, index) in F_DepartmentData" :key="index" :label="item.F_FullName"
                :value="item.F_DepartmentId"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- 考勤组id -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('考勤组id')" prop="F_AttendanceGroupId">
            <el-input v-model="formData['F_AttendanceGroupId']" placeholder="请输入考勤组id"
              :disabled="hasDisabledPermission('F_AttendanceGroupId', false)"
              :readonly="!hasEditPermission('F_AttendanceGroupId', false)" clearable :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 考勤组名称 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('考勤组名称')" prop="F_AttendanceGroupName">
            <el-input v-model="formData['F_AttendanceGroupName']" placeholder="请输入考勤组名称"
              :disabled="hasDisabledPermission('F_AttendanceGroupName', false)" :readonly="true" clearable
              :style="{ width: '100%' }"></el-input>
          </el-form-item>
        </el-col>
        <!-- 考勤组组长 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('考勤组组长')" prop="F_Group_Manager_id">
            <el-input v-model="formData['F_Group_Manager_id']" placeholder="请输入考勤组组长" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 申请人ID -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('申请人ID')" prop="F_UserId">
            <el-input v-model="formData['F_UserId']" placeholder="请输入申请人ID" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 申请人姓名 -->
        <el-col :span="24">
          <el-form-item :label="$t('申请人姓名')" prop="F_UserName">
            <el-input v-model="formData['F_UserName']" placeholder="请输入申请人姓名" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 申请时间 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('申请时间')">
            <el-input v-model="formData['F_CreateTime']" placeholder="请输入申请时间" :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 换班人 -->
        <el-col :span="24" v-if="hasFormPermission('F_UserId')">
          <el-form-item :label="$t('换班人')" prop="F_UserId">
            <avue-information-body :operationVal="operationVal" infoType='user' :whetherToRebindSecondaryEditing='false'
              v-model="formData['F_UserId']" placeholder="当前用户" :disabled="hasDisabledPermission('F_UserId', true)"
              :readonly="!hasEditPermission('F_UserId', true)" :style="{ width: '100%' }">
            </avue-information-body>
          </el-form-item>
        </el-col>
        <!-- 换班日期 -->
        <el-col :span="24" v-if="hasFormPermission('F_ChangeTime')">
          <el-form-item :label="$t('换班日期')" prop="F_ChangeTime">
            <el-date-picker :disabled="hasDisabledPermission('F_ChangeTime', false)" @blur="selectHuanBan"
              :readonly="!hasEditPermission('F_ChangeTime', false)" v-model="formData['F_ChangeTime']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{ width: '100%' }" placeholder="请选择换班日期" clearable>
            </el-date-picker>
          </el-form-item>
        </el-col>
        <!-- 换班班次 -->
        <el-col :span="24">
          <el-form-item :label="$t('换班班次')" prop="F_From">
            <el-select v-model="formData['F_From']" placeholder="请选择换班班次"
              :disabled="hasDisabledPermission('F_From', false)" filterable clearable :style="{ width: '100%' }">
              <el-option v-for="(item, index) in F_User_Replace_beforeOptions" :label="item.label" :value="item.value"
                :key="index">
              </el-option>

            </el-select>

          </el-form-item>
        </el-col>
        <!-- 替班人id -->
        <el-col :span="24" v-if="hasFormPermission('F_ReplaceId')" v-show="showFlag">
          <el-form-item :label="$t('替班人id')" prop="F_ReplaceId">
            <el-input v-model="formData['F_ReplaceId']" placeholder="请输入替班人id"
              :disabled="hasDisabledPermission('F_ReplaceId', false)"
              :readonly="!hasEditPermission('F_ReplaceId', false)" clearable :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 替班人姓名 -->
        <el-col :span="24" v-if="hasFormPermission('F_ReplaceName')">
          <el-form-item :label="$t('替班人姓名')" prop="F_ReplaceName">
            <el-input v-model="formData['F_ReplaceName']" placeholder="请输入替班人姓名"
              :disabled="hasDisabledPermission('F_ReplaceName', false)" @focus="selectNumberShow"
              :readonly="!hasEditPermission('F_ReplaceName', false)" clearable :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
          <div class="city_list" v-show="numberFlag">
            <div class="city_list_top">
              <el-input v-model="userName" placeholder="请根据姓名进行查询"></el-input>
            </div>
            <ul class="ul-class">
              <li v-for="(item, index) in filterNumbers" :key="index" @click="selectNumbers(item)">{{ item.realName }}
              </li>
            </ul>
            <div class="btnsss">
              <div class="height8"></div>
              <el-button size="mini" @click="close">取消</el-button>
            </div>
          </div>
        </el-col>
        <!-- 还班日期 -->
        <el-col :span="24" v-if="hasFormPermission('F_ReplaceTime')">
          <el-form-item :label="$t('还班日期')" prop="F_ReplaceTime">
            <el-date-picker :disabled="hasDisabledPermission('F_ReplaceTime', false)" @blur="selectHuanBan1"
              :readonly="!hasEditPermission('F_ReplaceTime', false)" v-model="formData['F_ReplaceTime']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{ width: '100%' }" placeholder="请选择还班日期" clearable>
            </el-date-picker>
          </el-form-item>
        </el-col>
        <!-- 还班班次 -->
        <el-col :span="24">
          <el-form-item :label="$t('还班班次')" prop="F_To">
            <el-select v-model="formData['F_To']" placeholder="请选择还班班次" :disabled="hasDisabledPermission('F_To', false)"
              filterable clearable :style="{ width: '100%' }">
              <el-option v-for="(item, index) in F_User_Return_beforeOptions" :key="index" :label="item.label"
                :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- 换班原因 -->
        <el-col :span="24">
          <el-form-item :label="$t('换班原因')" prop="F_Reasons">
            <el-input v-model="formData['F_Reasons']" type="textarea" placeholder="请输入换班原因"
              :disabled="hasDisabledPermission('F_Reasons', false)" :readonly="!hasEditPermission('F_Reasons', false)"
              :autosize="{ minRows: 4, maxRows: 4 }" :style="{ width: '100%' }"></el-input>
          </el-form-item>
        </el-col>
        <!-- 上传附件 -->
        <el-col :span="24" v-if="hasFormPermission('F_FileUrl')">
          <el-form-item :label="$t('上传附件')" prop="F_FileUrl">
            <xjr-custom-upload :config="F_FileUrlConfig" :disabled="hasDisabledPermission('F_FileUrl', false)"
              v-model="formData['F_FileUrl']" list-type="text"></xjr-custom-upload>
          </el-form-item>
        </el-col>
        <!-- 已生效 -->
        <el-col :span="24" v-if="hasFormPermission('F_IsEffective')" v-show="showFlag">
          <el-form-item :label="$t('已生效')" prop="F_IsEffective">
            <el-input v-model="formData['F_IsEffective']" placeholder="请输入已生效"
              :disabled="hasDisabledPermission('F_IsEffective', false)"
              :readonly="!hasEditPermission('F_IsEffective', false)" clearable :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 意见簿 -->
        <el-col :span="24" v-if="hasWorkFlowFormPermission('field12175bf')" v-show="optionsFlag">
          <el-form-item :label="$t('意见簿')" prop="field12175bf">
            <xjr-opinion-comonent :value="formData.field12175bf"></xjr-opinion-comonent>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="!isWorkflowForm">
          <el-form-item size="large" v-if="isEdit">
            <el-button type="primary" @click="submitForm" :loading="submitLoading">
              {{ submitLoading ? $t('workFlow.WFMenu.hintSubmit') : $t('submit') }}</el-button>
            <el-button @click="cancelForm">{{ $t('cancelText') }}</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import FilterableDataList from '@/components/generator/clientComponents/FilterableDataList.vue';
import workflowFormAuthorize from "@/mixins/workflowFormAuthorize";
import authorizeMixin from "@/mixins/authorize";
import { baseUrl } from "@/config/env";
import request from "@/router/axios";
import { getUserDetailsById, getGroupMembers, getSchedualTimes, getGroupDetails } from '@/api/user.js';
export default {
  mixins: [authorizeMixin, workflowFormAuthorize],
  components: {},
  props: ['keyValue', 'isEdit', 'disabled'],
  data() {
    let _this = this
    return {
      submitLoading: false,
      showForm: true,
      showFormKey: 1,
      reRenderSubform: false,
      operationVal: 'add',
      isAdd: true,
      addressUrl: 'exchange_class',
      mainTableName: 'oa_exchange_class',
      formConfig: {},
      formData: {
        'field100ae92': '',
        'F_AttendanceGroupId': '',
        'F_AttendanceGroupName': '',
        'F_UserId': '', // 申请人id
        'F_ChangeTime': null,
        'F_From': '',
        'F_ReplaceTime': null,
        'F_ReplaceId': '',
        'F_ReplaceName': '',
        'F_To': '',
        'F_Reasons': '',
        'F_FileUrl': null,
        'F_IsEffective': "0",
        'field12175bf': null,
        'F_RoleId': '', // 角色id
        'F_RoleName': '', // 角色名称
        'F_Area': '', // 地区
        'F_Job': '', // 职级名称
        'F_CreateTime': '',
        'F_DepartmentName': '', // 部门名称
        'F_DepartmentId': '', // 部门id
        'F_UserName': '', // 申请人姓名
        'F_Group_Manager_id': '', // 考勤组组长
      },
      rules: {
        F_DepartmentId: [{
          required: true,
          message: '请选择部门',
          trigger: 'change'
        }],
        F_AttendanceGroupId: [{
          required: true,
          message: '请输入考勤组id',
          trigger: 'blur'
        }],
        F_AttendanceGroupName: [{
          required: true,
          message: '请输入考勤组名称',
          trigger: 'blur'
        }],
        F_ChangeTime: [{
          required: true,
          message: '请选择换班日期',
          trigger: 'change'
        }],
        F_From: [{
          required: true,
          message: '请选择换班班次',
          trigger: 'change'
        }],
        F_ReplaceTime: [{
          required: true,
          message: '请选择还班日期',
          trigger: 'change'
        }],
        F_ReplaceId: [{
          required: true,
          message: '请输入替班人id',
          trigger: 'blur'
        }],
        F_ReplaceName: [{
          required: true,
          message: '请输入替班人姓名',
          trigger: 'change'
        }],
        F_To: [{
          required: true,
          message: '请选择还班班次',
          trigger: 'change'
        }],
        F_Reasons: [{
          required: true,
          message: '请输入换班原因',
          trigger: 'blur'
        }],
        F_FileUrl: [],
        F_IsEffective: [{
          required: true,
          message: '请输入已生效',
          trigger: 'blur'
        }],
      },
      F_User_Replace_beforeOptions: [],
      F_User_Return_beforeOptions: [],
      F_User_Return_afterOptions: [{
        "label": "选项一",
        "value": 1
      }, {
        "label": "选项二",
        "value": 2
      }],
      F_FileUrlConfig: {
        "showTip": false,
        "fileSize": 2,
        "sizeUnit": "MB",
        "buttonText": "点击上传",
        "disabled": false
      },
      groupId: '',
      numbers: [],
      userName: '',
      numberFlag: false,
      wgsValue: [],
      wgsValue1: [],
      F_DepartmentData: [],
      showFlag:false
    }
  },
  computed: {
    filterNumbers() {
      let self = this
      let numnerData = []
      if (!self.userName) {
        numnerData = self.numbers
      } else {
        self.numbers.forEach(e => {
          if (e.realName.includes(self.userName)) {
            numnerData.push(e)
          }
        })
      }
      return numnerData
    },
  },
  watch: {
    'formData.F_ReplaceName'(val) {
      if (val) {
        this.formData.F_ReplaceTime = null
        this.formData.F_To = ''
      }
    }
  },
  async created() {
    this.formConfig = this.getFormConfig();
  },
  async mounted() {
    //TODO   再这里做数据回填 请求表单数据
    if (this.keyValue) {
      this.isAdd = false;
    }
    if (!this.isAdd && this.keyValue) {
      this.operationVal = 'edit';
      try {
        let res = await request({
          url: baseUrl + "/" + this.addressUrl + "/" + this.keyValue,
          method: "get",
        });
        this.formData = res.data.data
        this.formId = this.formData.F_UserId
        this.showFormKey++;
      } catch (error) { }
    }
    this.getUserInfo()
    this.selectHuanBan()
    this.selectHuanBan1()
  },
  methods: {
    getFormData() {
      let key = this.mainTableName + 'Entity';
      let returnParams = {};
      returnParams[key] = this.formData;
      return {
        ...returnParams,
      };
    },
    validateForm() {
      this.$refs['elForm'].validate(valid => { });
    },
    async aysncValidateForm() {
      let validataArry = []
      validataArry.push(new Promise((resolve, reject) => {
        this.$refs['elForm'].validate(valid => {
          resolve(valid)
        })
      }))
      let res = await Promise.all(validataArry)
      if (res.includes(false)) {
        return false
      }
      else {
        return true;
      }
    },
    changeTableData() { },
    async submitForm() {
      this.submitLoading = true;
      let valid = await this.aysncValidateForm();
      if (valid == false) {
        this.submitLoading = false;
        return false;
      }
      // this.changeTableData();
      //格式化数据
      let newObj = this.getFormData();
      //如果没有传入参数就是新增
      if (!this.keyValue) {
        request({
          url: baseUrl + "/" + this.addressUrl,
          method: "post",
          data: newObj
        }).then((res) => {
          this.submitLoading = false;
          this.$notify({
            title: "成功",
            message: "新增成功",
            type: "success",
          });
          this.$emit("onChange", true)
        });

      }
      else {

        request({
          url: baseUrl + "/" + this.addressUrl + "/" + this.keyValue,
          method: "put",
          data: newObj
        }).then((res) => {
          this.submitLoading = false;
          this.$notify({
            title: "成功",
            message: "修改成功",
            type: "success",
          });
          this.$emit("onChange", true)
        });

      }



    },
    cancelForm() {
      this.$emit("onChange", true)
    },
    formatTree(data, valueField, lableField, childField, type) {
      let tree = [];
      data.forEach((node, index) => {
        let newNode = {
          value: node[valueField],
          label: node[lableField],
        };
        if (type) {
          newNode.disabled = node[valueField] == undefined ? true : false
        }
        tree.push(newNode);
        if (node[childField] != null && node[childField].length > 0) {
          newNode.children = (this.formatTree(node[childField], valueField, lableField, childField,
            type));
        }
      }, this);
      return tree;
    },
    //辅助工作流 审批(编辑) 预留方法
    handleEdit() {
    },
    //子表单权限
    getAuthorityTableChildrenList(bindTable, children) {
      let column = [];
      if (bindTable && this.formEnCodeList && this.formEnCodeList[bindTable]) {
        let formSubEnCodeList = this.formEnCodeList[bindTable];
        if (children && children.length > 0) {
          column = children.map(ele2 => {
            if (formSubEnCodeList.includes(ele2.prop)) {
              ele2.hide = false;
            }
            else {
              ele2.hide = true;
            }
            if (ele2.hide == false) {
              //工作流中系统表单必填权限
              if (this.formSubTableNotRequiredList[bindTable] != undefined) {
                if (this.formSubTableNotRequiredList[bindTable].includes(ele2.prop)) {
                  ele2.required = false;
                }
                else {
                  ele2.required = true;
                }
              }
              ele2.rules = [];
              if (ele2.required) {
                ele2.rules = ele2.ruleList;
              }
              // disabled 属性
              if (this.formSubTableDisabledList[bindTable] != undefined) {
                if (this.formSubTableDisabledList[bindTable].includes(ele2.prop)) {
                  ele2.disabled = true;
                }
                else {
                  ele2.disabled = false;
                }
              }
            }
            return ele2;
          });
        }
        return column;
      }
      else {
        return children;
      }
    },
    getFormConfig() {
      let config = {
        "fields": [{
          "__vModel__": "field100ae92",
          "__config__": {
            "label": "换班申请",
            "showLabel": false,
            "titleColor": null,
            "fontSize": null,
            "tag": "h2",
            "span": 24,
            "align": "top",
            "justify": "start",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 100
          }
        },

        //申请时间
        {
          "__vModel__": "F_CreateTime",
          "__config__": {
            "label": "申请时间",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 136,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_CreateTime",
            "bindTableFieldType": "varchar"
          }
        },
        //角色id
        {
          "__vModel__": "F_RoleId",
          "__config__": {
            "label": "角色id",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 136,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_RoleId",
            "bindTableFieldType": "varchar"
          }
        },
        //角色名称
        {
          "__vModel__": "F_RoleName",
          "__config__": {
            "label": "角色名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 135,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_RoleName",
            "bindTableFieldType": "varchar"
          }
        },
        //地区
        {
          "__vModel__": "F_Area",
          "__config__": {
            "label": "地区",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 134,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_Area",
            "bindTableFieldType": "varchar"
          }
        },
        // 部门id
        {
          "__vModel__": "F_DepartmentId",
          "__type__": "info",
          "infoType": "department",
          "__organize__": true,
          "__config__": {
            "label": "部门id",
            "showLabel": true,
            "tag": "avue-information-body",
            "avueType": "information-body",
            "defaultValue": "aebcb1b5e8f40ffc5f2b1bee84ffecd2",
            "required": true,
            "span": 24,
            "whetherToRebindSecondaryEditing": false,
            "bindTableField": "F_DepartmentId",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 133,
            "placeholder": "部门id",
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableFieldType": "varchar"
          }
        },
        //部门名称
        {
          "__vModel__": "F_DepartmentName",
          "__config__": {
            "label": "部门名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 132,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_DepartmentName",
            "bindTableFieldType": "varchar"
          }
        },
        //申请人id
        {
          "__vModel__": "F_UserId",
          "__config__": {
            "label": "申请人id",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 130,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_UserId",
            "bindTableFieldType": "varchar"
          }
        },
        //申请人姓名
        {
          "__vModel__": "F_UserName",
          "__config__": {
            "label": "申请人姓名",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 131,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_UserName",
            "bindTableFieldType": "varchar"
          }
        },
        //职级
        {
          "__vModel__": "F_Job",
          "__config__": {
            "label": "职级",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 137,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_Job",
            "bindTableFieldType": "varchar"
          }
        },
        //考勤组组长
        {
          "__vModel__": "F_Group_Manager_id",
          "__config__": {
            "label": "考勤组组长",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 138,
            "fieldLength": 500,
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_Group_Manager_id",
            "bindTableFieldType": "varchar"
          }
        },
        {
          "__vModel__": "F_AttendanceGroupId",
          "__config__": {
            "label": "考勤组id",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 101,
            "fieldLength": "50",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_AttendanceGroupId",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_AttendanceGroupName",
          "__config__": {
            "label": "考勤组名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 102,
            "fieldLength": "50",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_AttendanceGroupName",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_UserId",
          "__type__": "info",
          "infoType": "user",
          "__organize__": true,
          "__config__": {
            "label": "换班人",
            "showLabel": true,
            "tag": "avue-information-body",
            "avueType": "information-body",
            "defaultValue": "316231f32f1f0e5a4c56bf855806b924",
            "required": false,
            "span": 24,
            "whetherToRebindSecondaryEditing": false,
            "bindTableField": "F_UserId",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 103,
            "placeholder": "当前用户",
            "fieldLength": "50",
            "bindTable": "oa_exchange_class",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "date",
          "__vModel__": "F_ChangeTime",
          "__config__": {
            "label": "换班日期",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "defaultValue": null,
            "showLabel": true,
            "span": 24,
            "required": true,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 106,
            "fieldLength": "50",
            "bindTableFieldType": "datetime",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_ChangeTime"
          }
        }, {
          "__vModel__": "F_From",
          "__config__": {
            "label": "换班班次",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 24,
            "required": true,
            "saveField": "",
            "showField": "",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 117,
            "fieldLength": "300",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_From",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "date",
          "__vModel__": "F_ReplaceTime",
          "__config__": {
            "label": "还班日期",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "defaultValue": null,
            "showLabel": true,
            "span": 24,
            "required": true,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 109,
            "fieldLength": "50",
            "bindTableFieldType": "datetime",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_ReplaceTime"
          }
        }, {
          "__vModel__": "F_ReplaceId",
          "__config__": {
            "label": "替班人id",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 119,
            "fieldLength": "50",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_ReplaceId",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_ReplaceName",
          "__config__": {
            "label": "替班人姓名",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 120,
            "fieldLength": "50",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_ReplaceName",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_To",
          "__config__": {
            "label": "还班班次",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 24,
            "required": true,
            "saveField": "",
            "showField": "",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 118,
            "fieldLength": "300",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_To",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "textarea",
          "__vModel__": "F_Reasons",
          "__config__": {
            "label": "换班原因",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "textarea",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 114,
            "fieldLength": "500",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_Reasons",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_FileUrl",
          "__config__": {
            "label": "上传附件",
            "tag": "el-upload",
            "avueType": "upload",
            "defaultValue": null,
            "showLabel": true,
            "required": false,
            "span": 24,
            "showTip": false,
            "buttonText": "点击上传",
            "fileSize": 2,
            "sizeUnit": "MB",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 115,
            "fieldLength": "500",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_FileUrl",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_IsEffective",
          "__config__": {
            "label": "已生效",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "defaultValue": "0",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 126,
            "fieldLength": "2",
            "bindTable": "oa_exchange_class",
            "bindTableField": "F_IsEffective",
            "bindTableFieldType": "int"
          }
        }, {
          "tempType": "textarea",
          "__vModel__": "field12175bf",
          "__type__": "opinion",
          "__config__": {
            "label": "意见簿",
            "showLabel": true,
            "tag": "xjr-opinion-comonent",
            "defaultValue": null,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 121
          }
        }]
      };
      return config;
    },
    //根据用户id获取用户详情信息
    getUserInfo() {
      let params
      if (this.formData.F_UserId) {
        params = {
          userId: this.formData.F_UserId
        }
      } else {
        params = {
          userId: this.$store.state.user.userInfo.F_UserId
        }
      }
      getUserDetailsById(params).then(res => {
        if (res.data.success) {
          this.formData['F_UserName'] = res.data.data.F_RealName//申请人id申请人姓名
          this.formData['F_UserId'] = res.data.data.F_UserId//申请人id
          this.formData['F_Area'] = res.data.data.F_Area//地区信息
          this.formData['F_Job'] = res.data.data.F_Job//职级信息
          this.F_DepartmentData = res.data.data.F_Department//部门信息
          this.F_RoleData = res.data.data.F_Role//角色信息
          this.initRoleData()
          if (res.data.data.schedualGroup) {
            this.groupId = this.formData['F_AttendanceGroupId'] = res.data.data.schedualGroup.id
            this.formData['F_AttendanceGroupName'] = res.data.data.schedualGroup.groupName
            //查询考勤组组长
            getGroupDetails(this.groupId).then(res => {
              if (res.data.data) {
                this.formData['F_Group_Manager_id'] = res.data.data.manageUserId
              }
            })
            //调用查询该考勤组下所有人员信息
            this.getGroupAllMembers()
            this.initDepartmentData()
          }
        }
      })
    },
    initDepartmentData(){
      if(this.F_DepartmentData && this.F_DepartmentData.length == 1){
        this.formData['F_DepartmentName'] = this.F_DepartmentData[0].F_FullName
        this.formData['F_DepartmentId'] = this.F_DepartmentData[0].F_DepartmentId
      }
    },
    initRoleData() {
      let roleId = []
      let roleName = []
      if (this.F_RoleData && this.F_RoleData.length > 0) {
        this.F_RoleData.forEach(e => {
          roleId.push(e.F_RoleId)
          roleName.push(e.F_FullName)
        })
      }
      this.formData['F_RoleId'] = roleId.join(',')
      this.formData['F_RoleName'] = roleName.join(',')
    },
    getGroupAllMembers() {
      getGroupMembers(this.groupId).then(res => {
        if (res.data.success) {
          let arr = []
          let resData = res.data.data
          if(resData.length > 0) {
            arr = resData.filter(ele => {
              return ele.realName != this.formData.F_UserName
            })
          }
          this.numbers = arr
        }
      })

    },
    selectNumbers(item) {
      this.formData['F_ReplaceId'] = item.userId
      this.formData['F_ReplaceName'] = item.realName
      this.numberFlag = false
    },
    selectNumberShow() {
      this.formData['F_ReplaceId'] = ''
      this.numberFlag = true
    },
    close() {
      this.numberFlag = false
    },
    selectHuanBan() {
      let _this = this
      _this.F_User_Replace_beforeOptions = []
      if (!this.formData['F_ChangeTime']) {
      } else {
        let params = {
          userId: this.formData['F_UserId'],
          date: this.formData['F_ChangeTime']
        }
        getSchedualTimes(params).then(res => {
          if (res && res.data && res.data.data) {
            if (res.data.data.length > 0) {
              res.data.data.forEach((e, index) => {
                if (e.isWork === 1) {
                  console.log(e)
                  e.workStr = JSON.parse(e.workStr)
                  e.workStr[e.timeIndex] = '(' + e.workStr[e.timeIndex].begin + '-' + e.workStr[e.timeIndex].end + ')'
                  _this.F_User_Replace_beforeOptions.push({
                    value: e.id,
                    label: "班次" + (index + 1) + e.workStr[e.timeIndex]
                  })
                }
              })
              //
              if (!this.isAdd) {
                this.formData['F_From'] = parseInt(this.formData['F_From'])
              }
            }
          }
        })
      }

    },
    selectHuanBan1(v) {
      //判断替班人有没有
      let _this = this
      _this.F_User_Return_beforeOptions = []
      console.log(v);
      if (v != 1) {
        if (!this.formData['F_ReplaceName']) {
          // this.$message.error("请选择替班人")
          this.formData['F_ReplaceTime'] = ''
          return
        }
      }
      if (!this.formData['F_ReplaceTime']) {
        // this.$message.error("还班日期不能为空")
      } else {
        let params = {
          userId: this.formData['F_ReplaceId'],
          date: this.formData['F_ReplaceTime']
        }
        getSchedualTimes(params).then(res => {
          if (res && res.data && res.data.data) {

            if (res.data.data.length > 0) {
              // _this.F_User_Replace_beforeOptions = []
              res.data.data.forEach((e, index) => {
                if (e.isWork === 1) {
                  e.workStr = JSON.parse(e.workStr)
                  e.workStr[e.timeIndex] = '(' + e.workStr[e.timeIndex].begin + '-' + e.workStr[e.timeIndex].end + ')'
                  _this.F_User_Return_beforeOptions.push({
                    value: e.id,
                    label: "班次" + (index + 1) + e.workStr[e.timeIndex]
                  })
                }
              })
              if (!this.isAdd) {
                this.formData['F_To'] = parseInt(this.formData['F_To'])
              }
            }
          }
        })
      }
    },
    selectDepartMent() {
      if (this.F_DepartmentData && this.F_DepartmentData.length > 0) {
        this.F_DepartmentData.forEach(e => {
          console.log(e);
          if (e.F_DepartmentId == this.formData['F_DepartmentId']) {
            this.formData['F_DepartmentName'] = e.F_ShortName
          }
        })
      }
    },
  }
}
</script>
<style scoped>
ul,
li {
  margin: 0;
  padding: 0;
  list-style: none;
}

.el-table__empty-block {
  width: 100% !important;
}

.avue-form__row {
  padding: 0 !important;
}

#editorphone {
  width: 375px;
  margin: 0 auto;
  border: 1px solid #E4E7ED;
  padding: 0 7.5px;
  background: #f5f6fa;
  height: 700px;
  overflow-y: auto;
  overflow-x: hidden;
  border-radius: 5px;
}

#editorphone .el-col {
  border-bottom: 1px solid #F2F2F2;
  background: #fff;
  margin-bottom: 0;
  padding: 0 15px 6px !important;
  width: 100%;
}

#editorphone .el-form-item__label {
  line-height: 20px
}

#editorphone .el-input-group .el-input__inner {
  background: #f5f6fa
}

#editorphone .el-input__inner {
  border: 0
}

#editorphone .el-input-group__append,
#editorphone .el-input-group__prepend {
  border: 0;
  background: #edeef2;
  color: #666;
}

#editorphone .el-input-group .el-input__prefix {
  left: 44px
}

#editorphone .el-input-group .el-input__suffix {
  right: 44px
}

#editorphone .el-form-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-flow: wrap;
}

#editorphone .el-form-item__label {
  float: none;
  min-width: 85px;
  width: auto !important;
  text-align: left;
  flex: auto;
}

#editorphone .tinymce .el-form-item__label {
  min-width: 100%;
}

#editorphone .el-form-item__content {
  margin-left: 0px !important;
  flex: auto;
  width: calc(100% - 95px);
}

#editorphone .avueFormNoLable .el-form-item__label,
#editorphone .avueFormNoLable .avue-crud__pagination {
  display: none;
}

#editorphone .avueFormNoLable .el-collapse-item__wrap,
#editorphone .avueFormNoLable .el-collapse {
  border-bottom: 0
}

#editorphone .avueFormNoLable .el-col {
  border-bottom: 0;
  padding-bottom: 0
}

#editorphone .el-form-item__content .el-button:first-child {
  margin-left: 90px;
}

.el-upload__tip {
  line-height: 1.2;
}

/************开始***************/
.city_list {
  width: 600px;
  height: auto !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
  position: absolute;
  z-index: 1000;
  background: #fff;
  left: 110px;
}

.city_list>ul>li:hover {
  cursor: pointer;
  color: #0063f5;
}

.city_list_top {
  width: 100%;
  height: 32px;
  background: rgb(232, 243, 255);
  border-radius: 4px;
  margin: 0 auto;
  position: relative;
  top: 0;
}

.ul-class {
  padding: 10px;
  overflow: scroll;
  height: 230px;
  display: flex;
  flex-direction: column;
}

.ul-class li {
  width: 100%;
  text-align: left;
  font-size: 14px;
}

.btnsss {
  width: 95%;
  margin: 0 auto;
  text-align: right;
  border-top: 1px solid rgb(228, 228, 228);
}

.height8 {
  height: 8px;
}

.flex {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

.city_list_top_items {
  width: 100px;
  height: 100%;
  line-height: 32px;
  font-size: 16px;
  color: #333;
  text-align: center;
}

.city_list_top_items:hover {
  cursor: pointer;
  color: #0063f5;
}

.close {
  text-align: right;
  line-height: 2em;
  color: #0063f5;
  font-size: 16px;
  margin-bottom: 8px;
}

/************结束***************/
</style>
